﻿using System.Collections.Generic;
using System.Text;

namespace PersonaLibrary.Search
{
	public class SearchCriteria
	{
		public SearchCriteria()
		{
			if(Operators!= null && Operators.Count > 0)
				Operator = Operators[0];
		}

		private List<string> _operators;

		public string Join { set; get; }

		public string Value { set; get; }

		public string Operator { set; get; }

		public string PropertyName { set; get; }

		public string DisplayName { set; get; }

		public virtual void CreateWhere(StringBuilder stringBuilder)
		{
			stringBuilder.Append(PropertyName);
			stringBuilder.Append(" ");
			stringBuilder.Append(Operator);
			stringBuilder.Append(" '");
			stringBuilder.Append(Value);
			stringBuilder.Append("'");
		}

		protected virtual List<string> CreateOperators()
		{
			return new List<string>{"=", "!="};
		}

		public List<string> Operators
		{
			get
			{
				if (_operators == null)
					_operators = CreateOperators();

				return _operators;
			}
		}

		public override string ToString()
		{
			return DisplayName;
		}
	}
}
